<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\Models\PriDeviceInfo;

class GenerateReal extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'generate:real {pdi}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'generate real data';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $pdi = $this->argument('pdi');
        if(!$pdi) {
            $this->error('device pdi index is required!');
        }
        $device = PriDeviceInfo::findOrFail($pdi);
        
        $typeId = $device->dpt_id;
        
        $models = config('device.map_models');
        
        $model = data_get($models, $typeId.'.real');
        $model::unguard();
        $model::create([
            'pdi_index'=>$pdi,
            'rd_updatetime'=> date('Y-m-d H:i:s')
        ]);
    }
}
